﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Entities;

namespace DAL
{
    public class QuestionRepository : IQuestionRepository
    {
        private QuestionContext context = new QuestionContext();

        public Question GetById(int questionId)
        {
            return context.Questions.SingleOrDefault(c => c.ID == questionId);
        }

        public IQueryable<Question> GetAll()
        {
            return context.Questions;
        }

        public void AddQuestion(Question q)
        {
            context.Questions.Add(q);
            context.SaveChanges();
        }

        public void UpdateQuestion(Question q, int stt, string mota)
        {
            Question t = context.Questions.First(c => c.ID == stt);
            t.MoTa = mota;
            context.SaveChanges();
        }

        public void DeleteQuestion(Question q)
        {
            context.Questions.Remove(q);
            context.SaveChanges();
        }



    }
}
